<?php

namespace App\Http\Requests\Train;

use Carbon\Carbon;
use Illuminate\Foundation\Http\FormRequest;

class TicketQueryRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            "from"       => "required",
            "from.type"  => "required|in:0,1,2",
            "from.code"  => "required",
            "to"         => "required",
            "to.type"    => "required|in:0,1,2",
            "to.code"    => "required",
            "train_date" => "required|date|after_or_equal:today",
        ];
    }


    public function messages()
    {
        return [
            "train_date.after_or_equal" => __('validation.after_or_equal', [
                'date'      => Carbon::today()->toDateString(),
                'attribute' => '出发',
            ]),
        ];
    }
}
